const path = require('path')
function resolve(dir) {
  return path.join(__dirname, dir)
}

function getCurrentDateTime() {
  var now = new Date();
  var year = now.getFullYear();
  var month = ('0' + (now.getMonth() + 1)).slice(-2);
  var date = ('0' + now.getDate()).slice(-2);
  var hour = ('0' + now.getHours()).slice(-2);
  var minute = ('0' + now.getMinutes()).slice(-2);
  var second = ('0' + now.getSeconds()).slice(-2);
  return year + month + date + hour + minute + second;
}
module.exports = {
  publicPath: process.env.NODE_ENV === 'production' ? '/vue3/app/dist' : '/',
  chainWebpack: config => {
    if (process.env.NODE_ENV === 'production') {
      const time = getCurrentDateTime();
      config.output.filename('js/[name]' + time + '.js').end();
      config.output.chunkFilename('js/[name]' + time + '.js').end();
      config.plugin('extract-css').tap(args => [{
        filename: 'css/[name]' + time + '.css',
        chunkFilename: 'css/[name]' + time + '.css'
      }])
    }
  },
  configureWebpack: {
    plugins: [
      require('unplugin-auto-import/webpack')({ 
        imports: ['vue', 'vue-router', 'vuex']
       }),
    ],
    resolve: {
      alias: {
        '@': resolve('src')
      }
    }
  },
}